import { reactive } from "vue";
import { TableDataType } from "@/shims/globe";
import { accountList } from "@/api/account-management";
// 组合式函数
export default function useAccountList(params: any) {
  // 返回格式
  const tableData: any = reactive<{
    data: TableDataType[];
    loading: boolean;
  }>({
    data: [],
    loading: false
  });
  // 查询列表
  const getAccountList = async () => {
    try {
      const {
        data: { datas }
      } = await accountList({
        ...params
      });
      tableData.data = datas.map((r: any) => {
        return {
          key: r.id,
          ...r
        };
      });
    } catch (e) {
      console.log(`object`, e);
    }
  }

  return {
    tableData,
    getAccountList
  }
}